package cn.lzd.mr.case8;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by lzd on 2018/8/9.
 */
public class Main {
    static int j = (10000 * 10000 * 100)+1;
    static Set<String> sets = new HashSet<>();
    static int h = 0;
    public static void main(String[] args) {

        for (int i = 1; i < j; i++) {
            String str = String.format("%011d", i);
            sets.add(str);
            if ((i % 10000000) == 0) {
                try {
                    FileUtils.writeLines(new File("D:/companycode/unique_code"+(++h)), sets,true);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                sets = new HashSet<>();
                System.gc();
                System.out.println("已处理=" + i);
            }
        }

        if(sets.size() != 0){
            try {
                FileUtils.writeLines(new File("D:/companycode/unique_code"+(++h)), sets,true);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("end ....");

    }
}
